package unamed.entities;

import basis.game.entities.Entity;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import unamed.Art.Art;

public class Blast extends Entity{
    
    private double angle;
    private double speed=2;
    private BufferedImage img;
    
    public Blast(double x,double y,double angle){
        super(x,y,20,20);
        this.angle=angle;
        img=generate();
    }
    
    private BufferedImage generate(){
        BufferedImage im=new BufferedImage(Art.blast.getWidth(),Art.blast.getHeight(),Art.blast.getType());
        int[] raw=new int[Art.blast.getWidth()*Art.blast.getHeight()];
        Art.blast.getRGB(0,0,Art.blast.getWidth(),Art.blast.getHeight(),raw,0,Art.blast.getWidth());
        for(int i=0;i<raw.length;i++){
            int alpha=raw[i]>>24&0xff;
            int red=raw[i]>>16&0xff;
            int green=raw[i]>>8&0xff;
            int blue=raw[i]&0xff;
            if(red<=50&&green<=50&&blue<=50){
                raw[i]=alpha<<24|(Blaster.color&0x00ffffff);
            }
        }
        im.setRGB(0,0,im.getWidth(),im.getHeight(),raw,0,im.getWidth());
        //im=Art.scale(im,(int)w,(int)h);
        return im;
    }
    
    @Override
    public void update(long t) {
        x+=speed*Math.cos(angle);
        y+=speed*Math.sin(angle);
    }

    @Override
    public void render(Graphics2D g) {
        g.drawImage(Art.rotate(img,angle),null,(int)x,(int)y);
    }
    
}